import wx from './index.js'
import api from '../../../api/api.js'
import url from '../../../api/config.js'
export default {
	isWechat: function() {
		var ua = window.navigator.userAgent.toLowerCase();
		if (ua.match(/micromessenger/i) == 'micromessenger') {
			// console.log('是微信客户端')
			return true;
		} else {
			// console.log('不是微信客户端')
			return false;
		}
	},
	initJssdk:function(callback){
		var uri = encodeURIComponent(window.location.href.split('#')[0]);//获取当前url然后传递给后台获取授权和签名信息  
		uni.request({
			url: url+api.link,
			data:{
				url: uri  
			},
			success:(res)=>{
				wx.config({
					debug: false,
					appId: res.data.signPackage.appId,
					timestamp: res.data.signPackage.timestamp,
					nonceStr: res.data.signPackage.nonceStr,
					signature: res.data.signPackage.signature,
					jsApiList: [
						'chooseImage',
						'previewImage',
						'uploadImage'
					]
				});
				if (callback) {  
					callback(res.data);  
				}
			}
		})
	}
}